﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Asistente.Model.Representation
{
    public class Query : DataGroup
    {
        public List<Entity> UsedEntities { get; set; }

        public Query() { /*Intencionalmente blanco*/ }

        public Query(List<Entity> entities) 
        {
            this.UsedEntities = entities;
            this.Name = getName(entities);
        }

        /// <summary>
        /// Returns a name for the query containing the names of the entities wich define the query
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        private String getName(List<Entity> entities){
            String name=entities[0].Name;
            for (int i = 1; i <= entities.Count-1;i++)
            {
                name += " - " + entities[i].Name;
            }
            return name;
        }

        public override string ToString()
        {
            return UsedEntities.Aggregate("", (current, entity) => current + (" " + entity.Name));
        }
    }
}
